﻿namespace DataScripter.Excel.Formatters
{
	internal class NumberFormatter : ICellFormatter
	{
		private int NrOfDecimals { get; set; }

		public NumberFormatter(int? nrOfDecimals)
		{
			NrOfDecimals = nrOfDecimals.HasValue ? nrOfDecimals.Value : 2;
		}

		#region Implementation of ICellFormatter

		public void Format(ICell cell)
		{
			// replicate a NrOfDecimals number of times zero
			const string MAX_ZEROES = "0000000000";
			string myNeededZeroes = MAX_ZEROES.Substring(0, NrOfDecimals);
			cell.NumberFormat = "#.##0," + myNeededZeroes;
		}

		#endregion
	}
}